package net.qiqbframework.common.utils;

import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class CollectionUtil {
    /**
     * 集合是否为空
     *
     * @param collection 集合
     * @return 是否为空
     */
    public static boolean isEmpty(Collection<?> collection) {
        return collection == null || collection.isEmpty();
    }

    public static boolean isNotEmpty(Collection<?> collection) {
        return !isEmpty(collection);
    }

    /**
     * 截取 list 中之后的所有元素，包括 target
     *
     * @param list
     * @param target
     * @return
     */
    public static List<?> subRemainingByTarget(List<?> list, Object target) {
        int index = list.indexOf(target);
        if (index != -1 && index < list.size()) {
            return list.subList(index, list.size());
        }
        return new ArrayList<>();
    }
}
